<?php

declare(strict_types=1);

namespace App\Model;

use Hyperf\DbConnection\Model\Model;

/**
 * 文章收藏模型
 */
class ArticleFavorite extends Model
{
    /**
     * 表名
     */
    protected ?string $table = 'article_favorites';

    /**
     * 可批量赋值的字段
     */
    protected array $fillable = [
        'user_id',
        'article_id',
        'folder_id'
    ];
    const UPDATED_AT = null;

    /**
     * 类型转换
     */
    protected array $casts = [
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
    ];

    /**
     * 关联用户
     */
    public function user()
    {
        return $this->belongsTo(\App\Model\User::class, 'user_id');
    }

    /**
     * 关联文章
     */
    public function article()
    {
        return $this->belongsTo(\App\Model\Articles::class, 'article_id');
    }

    /**
     * 关联收藏夹
     */
    public function folder()
    {
        return $this->belongsTo(\App\Model\FavoriteFolder::class, 'folder_id');
    }
}